Custom Hooks lets you share stateful logic, not the state itself. Each call to a Hook is completely independent from every other call to the same Hook.
The code inside your custom Hooks will re-run during every re-render of your component. This is why, like components, custom Hooks need to be pure. Think of custom Hooks’ code as part of your component’s body!
Because custom Hooks re-render with your component, they always receive the latest props and state.
A good custom Hook makes the calling code more declarative by constraining what it does.
Imagine you need to fetch data in a component and you decide to extract the logic into a custom hook. Walk me through how you'd implement that hook and what you need to watch out for regarding dependencies and cleanup.
If you forget to include a value in the dependency array of a useEffect inside a custom hook, what could go wrong and how would you notice it?
How would you make sure a custom hook you write doesn't cause unnecessary re‑renders in components that consume it?
You have a custom hook that subscribes to a WebSocket and updates state. During a code review a teammate points out that the hook sometimes leaks listeners after the component unmounts. How would you debug and fix it?
When you compose several custom hooks together, you notice the order of hook calls changes the behavior. Explain why order matters and how you'd structure them to avoid bugs.
Suppose you need to share a piece of state across several unrelated components using a custom hook. What patterns would you consider and what trade‑offs do they have?
Our app has dozens of components using a custom hook that caches API responses, and under heavy load we see memory usage growing. How would you redesign the hook to be more memory‑efficient while preserving its public API?
We want to expose a library of custom hooks to other teams. What guidelines would you set for naming, error handling, and testing to ensure consistency and maintainability?
A custom hook uses useRef to store mutable values, but a bug appears when the ref is accessed before it's initialized. How would you safeguard against this in the hook's implementation?
We are planning to replace several duplicated data‑fetching hooks across multiple services with a unified data layer. How would you approach the migration and what architectural considerations would you keep in mind for the custom hook design?
Our organization wants to enforce a policy that all side‑effectful logic lives in custom hooks. What cross‑team standards, lint rules, and runtime checks would you propose to ensure compliance and avoid performance regressions?
When scaling to server‑side rendering and streaming, what challenges do custom hooks present and how would you adapt our hook implementations to work correctly in both client and SSR environments?